package com.aier.school.action;

import java.sql.Timestamp;
import java.util.Date;
import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Component;

import com.aier.classes.entity.InviteTeacher;
import com.aier.classes.service.IInviteRequestService;
import com.aier.common.dao.ICommonDAO;
import com.aier.school.common.SchoolFinalPageSize;
import com.aier.school.entity.SchoolGrade;
import com.aier.school.service.ISchoolService;

@Scope("prototype")
@Component("schoolTeacherInviteAction")
public class SchoolTeacherInviteAction extends SchoolBaseAction{

    /**
     * 学校管理-教师邀请
     */
    private static final long serialVersionUID = 1L;

    @Resource(name = "schoolService")
    private ISchoolService schoolService;    
    @Resource(name = "inviteRequestService")
    private IInviteRequestService inviteRequestService;    
    
    private int s;                //成功:1 ,失败:0
    private String error_info;    //错误提示信息
        
    private Integer sid;        //学校id
    private List<SchoolGrade> schoolGradeList;    //职务列表
    private List<InviteTeacher> inviteTeacherList;    //教师邀请记录列表
    private Long itid;            //教师邀请id
    private String tname;        //教师姓名
    private String phone;        //手机号
    private Long gid;            //职务id
    private Long tid;            //发送邀请的教师tid
    
    private int page;            //页数
    private int page_size;        //每页的记录数
    private int page_count;        //总页数
    private int count;            //总数
    
    @Override
    public String execute(){
        schoolGradeList = schoolService.searchSchoolGradeList(sid);
        
        return SUCCESS;
    }
    
    /**
     * 查询学校邀请记录
     * @return
     */
    @SuppressWarnings("unchecked")
    public String searchTeacherInviteList(){
        s = 1;
        Map<String,Object> map = inviteRequestService.searchInviteTeacherList(page, SchoolFinalPageSize.TEACHER_INVITE_LIST_PAGESIZE, null, sid);
        if(null==map){
            s = 0;
        }
        inviteTeacherList = (List<InviteTeacher>) map.get(ICommonDAO.OBJ_LIST);
        if (null == inviteTeacherList) {
            s = 0;
        }
        page = (Integer) map.get(ICommonDAO.PAGE);
        page_size = (Integer) map.get(ICommonDAO.PAGE_SIZE);
        page_count = (Integer) map.get(ICommonDAO.PAGE_COUNT);
        count = (Integer) map.get(ICommonDAO.COUNT);
        return SUCCESS;
    }

    /**
     * 添加教师邀请
     * @return
     */
    public String addTeacherInvite(){
        Timestamp ctime = new Timestamp(new Date().getTime());
        if(gid==-1){
            gid = null;
        }
        InviteTeacher inviteTeacher = new InviteTeacher(null, tname, phone, gid, sid, null, tid, null, ctime);
        s = inviteRequestService.insertInviteTeacher(inviteTeacher);
        return SUCCESS;
    }
    
    /**
     * 删除教师邀请记录
     * @return
     */
    public String deleteTeacherInvite(){
        s = inviteRequestService.deleteInviteTeacher(itid);
        return SUCCESS;
    }

    public int getPage() {
        return page;
    }

    public void setPage(int page) {
        this.page = page;
    }

    public int getPage_size() {
        return page_size;
    }

    public void setPage_size(int page_size) {
        this.page_size = page_size;
    }

    public int getPage_count() {
        return page_count;
    }

    public void setPage_count(int page_count) {
        this.page_count = page_count;
    }

    public int getCount() {
        return count;
    }

    public void setCount(int count) {
        this.count = count;
    }

    public int getS() {
        return s;
    }

    public String getError_info() {
        return error_info;
    }

    public List<SchoolGrade> getSchoolGradeList() {
        return schoolGradeList;
    }

    public List<InviteTeacher> getInviteTeacherList() {
        return inviteTeacherList;
    }

    public void setSchoolService(ISchoolService schoolService) {
        this.schoolService = schoolService;
    }

    public void setInviteRequestService(IInviteRequestService inviteRequestService) {
        this.inviteRequestService = inviteRequestService;
    }

    public void setSid(Integer sid) {
        this.sid = sid;
    }

    public void setItid(Long itid) {
        this.itid = itid;
    }

    public void setTname(String tname) {
        this.tname = tname;
    }

    public void setPhone(String phone) {
        this.phone = phone;
    }

    public void setGid(Long gid) {
        this.gid = gid;
    }

    public void setTid(Long tid) {
        this.tid = tid;
    }

    public Integer getSid() {
        return sid;
    }

    public Long getTid() {
        return tid;
    }
    

}